package com.jack.thinking.thread.core._3;

public class JoinUnexpect {
	public static void main(String[] args) {
		try {
			ThreadB b = new ThreadB();
			ThreadA a = new ThreadA(b);
			a.start();
			b.start();
			b.join(2000);
			System.out.println(" main end" + System.currentTimeMillis()/1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}


class ThreadA extends Thread{
	private ThreadB b;
	
	public ThreadA(ThreadB b) {
		this.b = b;
	}
	
	@Override
	public void run() {
		try {
			synchronized (b) {
				System.out.println("begin A threadName = " + Thread.currentThread().getName() + "   " + System.currentTimeMillis()/1000);
				Thread.sleep(5000);
				System.out.println("  end A threadName = " + Thread.currentThread().getName() + "   " + System.currentTimeMillis()/1000);
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}

class ThreadB extends Thread{
	@Override
	synchronized public void run() {
		try {
			System.out.println("begin B threadName = " + Thread.currentThread().getName() + "   " + System.currentTimeMillis()/1000);
			Thread.sleep(5000);
			System.out.println("  end B threadName = " + Thread.currentThread().getName() + "   " + System.currentTimeMillis()/1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}